﻿using DG.Tweening;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Miao.UI
{
    /// <summary>
    /// 使用Animation播放
    /// 在Animation中绑定需要播放的动画切片
    /// </summary>
    public class AnimationUIMotion : BaseUIMotion
    {
        //AnimationClip animationClip;
        public AnimationUIMotion()
        {
            

        }

        public override void Play(bool forward, TweenCallback complete)
        {
            Animation animation = TweenGameObject.GetComponent<Animation>();
            //迷惑的Unity老动画播放索引
            int index = forward? 0 : 1;
            int currentIndex = 0;
            foreach (AnimationState state in animation)
            {
                if (currentIndex == index)
                {
                    animation.Play(state.name);
                    DOVirtual.DelayedCall(state.length,complete);

                    break;
                }
                currentIndex++;
            }



        }
    }
}
